using log4net;
using System;
using System.IO;
namespace CommandLib.Base
{
	public class Log
	{
		public static ILog Log4 = LogManager.GetLogger("SQ");
		private static object lckobj = new object();
		public static void ErrorLogWirte(Exception ex, string path)
		{
			lock (Log.lckobj)
			{
				string directoryName = Path.GetDirectoryName(path);
				if (!Directory.Exists(directoryName))
				{
					path = Directory.CreateDirectory(directoryName).FullName;
				}
				string path2 = path;
				if (!File.Exists(path2))
				{
					using (FileStream fileStream = File.Create(path2))
					{
						fileStream.Close();
					}
				}
				using (TextWriter textWriter = File.AppendText(path2))
				{
					textWriter.WriteLine("\r\n-------------------------------------------------------------------------------------------------");
					textWriter.WriteLine("时间：" + DateTime.Now.ToString());
					textWriter.WriteLine("错误信息：" + ex.Message);
					textWriter.WriteLine("详细信息： \r\n" + ex.StackTrace);
					textWriter.WriteLine();
					textWriter.Close();
				}
			}
		}
		public static void WriteLog4(string LogContent, byte[] buff, LOGTYPE LogType)
		{
			Log.WriteLog4(LogContent + ByteHelper.BytesToHexString(buff), LogType);
		}
		public static void WriteLog4(string LogContent, LOGTYPE LogType)
		{
			switch (LogType)
			{
				case LOGTYPE.DEBUG:
				{
					Log.Log4.Debug(LogContent);
					break;
				}
				case LOGTYPE.INFO:
				{
					Log.Log4.Info(LogContent);
					break;
				}
				case LOGTYPE.WARN:
				{
					Log.Log4.Warn(LogContent);
					break;
				}
				case LOGTYPE.ERRORD:
				{
					Log.Log4.Error(LogContent);
					break;
				}
				case LOGTYPE.FETAL:
				{
					Log.Log4.Fatal(LogContent);
					break;
				}
			}
		}
		public static void WriteLog4Ex(string LogContent, Exception ex)
		{
			Log.WriteLog4(LogContent + ":" + ex.ToString(), LOGTYPE.ERRORD);
		}
	}
}
